package org.yjc.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="yjc_student")
public class Student {
	private Integer id; //id
	private String name; //姓名
	private String stuNum; //学号
	private String sex; //性别
	private String userName; //用户名
	private String passWord; //密码
	private TbClass tbClass; //班级对象
	private Integer cj;
	@JsonIgnore
	private List<Course> courses=new ArrayList<>();
	@JsonIgnore
	private List<Grade> grades=new ArrayList<>();
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=10)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(length=10)
	public String getStuNum() {
		return stuNum;
	}
	public void setStuNum(String stuNum) {
		this.stuNum = stuNum;
	}
	@Column(length=10)
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	@Column(length=10)
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	@Column(length=10)
	public String getPassWord() {
		return passWord;
	}
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	@ManyToOne
	public TbClass getTbClass() {
		return tbClass;
	}
	public void setTbClass(TbClass tbClass) {
		this.tbClass = tbClass;
	}
	@OneToMany(mappedBy="student")
	public List<Grade> getGrades() {
		return grades;
	}
	public void setGrades(List<Grade> grades) {
		this.grades = grades;
	}
	
	public Integer getCj() {
		return cj;
	}
	public void setCj(Integer cj) {
		this.cj = cj;
	}
	public Student(Integer id, String name, String stuNum, String sex, String userName, String passWord,
			TbClass tbClass, List<Course> courses, List<Grade> grades) {
		super();
		this.id = id;
		this.name = name;
		this.stuNum = stuNum;
		this.sex = sex;
		this.userName = userName;
		this.passWord = passWord;
		this.tbClass = tbClass;
		this.courses = courses;
		this.grades = grades;
	}
	public Student() {
		super();
	}
	
	@Transient//�ǳ־û�
	public List<Course> getCourses() {
		List<Course> courses=new ArrayList<>();
		for (Grade grade : getGrades()) {
			courses.add(grade.getCourse());
		}
		return courses;
	}
	
	@Transient
	public String getCourseNames() {
		String str="";
		for (Course course : getCourses()) {
			str+=course.getCourseName()+",";
		}
		if(str.length()>0) {
			str=str.substring(0,str.length()-1);
		}
		return str;
	}
	
	
	
}
